package com.example.pceb.controller;

import com.example.pceb.entity.BorrowRecord;
import com.example.pceb.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin(origins = "*")
@RequestMapping("/api/borrow")
public class BorrowController {
    @Autowired
    private BorrowService borrowService;

    @PostMapping("/borrow")
    public void borrow(@RequestParam Long resourceId, @RequestParam String username) {
        borrowService.borrow(resourceId, username);
    }

    @PostMapping("/return")
    public void returnResource(@RequestParam Long recordId) {
        borrowService.returnResource(recordId);
    }

    @GetMapping("/records")
    public List<BorrowRecord> records() {
        return borrowService.listRecords();
    }
}
